<template>
    <a-table :scroll="{ y: 240 }" bordered :pagination="false" :columns="getColumns()" :dataSource="getData()">
    </a-table>
</template>
<script setup lang="ts">

const props = defineProps<{
    Data: string[][]
}>()

const columns = [
    {
        title: '科室',
        dataIndex: 'department',
        width: 120,
        align: 'center'
    }
]

function getColumns() {
    const dateArr = props.Data[0].slice(1).map(item => ({
        title: item,
        dataIndex: item,
        width: 80,
        align: 'center'
    }))
    return columns.concat(dateArr)
}

getData()
function getData() {
    const dateArr = props.Data[0].slice(1)
    const result = props.Data.slice(1).map(row => {
        const obj: Record<string, number | string> = {}
        row.slice(1).forEach((value, index) => {
            if (index < dateArr.length) {
                obj.department = row[0]
                obj[dateArr[index]] = value
            }
        })
        return obj
    })
    return result
}

</script>
<style lang="scss" scoped></style>